﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using Demo.Attribute.Validation;

namespace Demo.Models.Dto
{
    public class EmployeeUpdateDto
    {
        [Display(Name = "员工编号")]
        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(10, MinimumLength = 10, ErrorMessage = "{0}的长度为{1}")]
        public string EmployeeNo { get; set; }

        [Display(Name = "名")]
        [Required(ErrorMessage = "{0}不能为空")]
        [MaxLength(50, ErrorMessage = "{0}的长度不能超过{1}")]
        public string FirstName { get; set; }

        [Display(Name = "姓")]
        [Required(ErrorMessage = "{0}不能为空")]
        [MaxLength(50, ErrorMessage = "{0}的长度不能超过{1}")]
        public string LastName { get; set; }


        [Display(Name = "性别")]
        [RegularExpression("[男|女]",ErrorMessage = "{0}有误")]
        public string Gender { get; set; }

        [Display(Name = "出生日期")] 
        public DateTime Birthday { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var age = DateTime.Today.Year - Birthday.Year;

            if (age < 0 || age > 120)
            {
                yield return new ValidationResult("用户出生日期不合法", new[] { nameof(Birthday) });
            }

            if (new[]{"男","女"}.Contains(Gender))
            {
                
            }
        }
    }
}